-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: adding a unit test to cover invalid code check in util.deprecate method #16305
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a nit
common.expectsError( | ||
() => { | ||
util.deprecate(() => {}, "message", 123); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: There's only one statement inside the function.
This can be converted to:
() => util.deprecate(() => {}, "message", 123)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing @akaila! This looks well on the way but there are a few nits that could be updated.
Also, I would recommend running the JS linter (make lint-js
) and fixing any problematic things that it flags. See our contributing guide for more info: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#the-process-of-making-changes
Please let me know if any of the info in there is unclear or doesn't work for you.
@@ -0,0 +1,17 @@ | |||
"use strict"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use single quotes for strings throughout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah my local workspace had prettier enabled which I have disabled now. Updated PR.
Thanks !
[1, true, false, null, {}].forEach(notString => { | ||
common.expectsError( | ||
() => { | ||
util.deprecate(() => {}, "message", 123); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think 123
was meant to be notString
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Fixed.
{ | ||
code: "ERR_INVALID_ARG_TYPE", | ||
type: global.TypeError, | ||
message: `The "code" argument must be of type string` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a plain single-quoted string instead of a template string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
}, | ||
{ | ||
code: "ERR_INVALID_ARG_TYPE", | ||
type: global.TypeError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: please remove the global.
part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
@akaila To make it easier to land this, you could also update your commit message to be 50 chars or less. If you need to provide more info, you can put in two new lines and then write the rest of it. See the specs for valid commit messages here: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#commit-message-guidelines Or whoever lands this can also do it later. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the linter caught one more issue. If you could fix that and potentially adjust the commit message as per above, that would be amazing! Thanks!
const common = require('../common'); | ||
const util = require('util'); | ||
|
||
[1, true, false, null, {}].forEach(notString => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caught by linter: this needs parens around notString
to be (notString)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akaila You can run linter just for Javascript files using make lint-js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok trying now.
const util = require('util'); | ||
|
||
[1, true, false, null, {}].forEach(notString => { | ||
common.expectsError(() => util.deprecate(() => { }, 'message', notString), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: would you mind removing the extra space inside { }
? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and I ran linter to ensure things look ok:
make lint-js
Running JS linter...
./node tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules --ext=.js,.mjs,.md
benchmark doc lib test tools
About update of diff in PR taking time, I've logged the issue with Github at isaacs/github#1098 |
Looking at the output, no idea why build should fail: |
CI was fine, we just have some failing tests at the moment which are being fixed elsewhere. |
I see. Do you have to override the failure to have it merge into master? Sorry if I am asking too many questions being a newbie :) |
@akaila Not at all, that's what we're here for :) Merging is just at the discretion of collaborators. As long as a pull request is approved (and not a single collaborator objects) and no CI failures are related to it, it can be merged. (Oh and at least 48 hours have to pass.) You can read more about the process here: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#step-10-landing (the whole doc is pretty useful in general) |
Test for invalid argument types passed to code on util.deprecate. PR-URL: #16305 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Thanks ! |
The new tests are failing on 8.x Would someone be willing to manually backport? |
What does backport mean here? I tested this on current master (8.7 I believe) and it passed. If you can give me an example of backport, I can definitely do it. |
Backporting instructions are given at https://github.com/nodejs/node/blob/e517bc97d48da199e5e3af858e19173a209063c4/doc/guides/backporting-to-release-lines.md |
Added backport PR. Please approve |
in retrospect this PR requires changes to using error codes that we cannot backport to 8.x as they are semver major. I am marking as don't land |
Test for invalid argument types passed to code on util.deprecate. PR-URL: nodejs/node#16305 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Test for invalid argument types passed to code on util.deprecate. PR-URL: #16305 Backport-PR-URL: #16430 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Test for invalid argument types passed to code on util.deprecate. PR-URL: #16305 Backport-PR-URL: #16430 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Test for invalid argument types passed to code on util.deprecate. PR-URL: nodejs/node#16305 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Added a unit test that verifies assertion if util.deprecate is called with a non-string code parameter.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
util.deprecate